package com.homwork.Collection_learn.Collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Exercise1 {
    public static void main(String[] args) {
        List<Dog> dogs = new ArrayList<>();
        for (int i = 0; i <3 ; i++) {
            Dog dog = new Dog();
            dog.setAge(11);
            dog.setName("xx");
            dogs.add(dog);
        }
        /**
         * 迭代器
         */
        System.out.println("迭代器");
        Iterator<Dog> dogIterator = dogs.iterator();
        while (dogIterator.hasNext()) {
            Dog next =  dogIterator.next();
            System.out.println(next);
        }
        /**
         * 增强for
         */
        System.out.println("增强for");
        for (Dog dog : dogs) {
            System.out.println(dog);
        }
    }
}

class Dog {
    private String name;

    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
